# -*- coding:utf-8 -*-
# -------------------------------------------------------------------------------
# Description:  
# Reference:
# Author: 安智军
# Date:   2021/12/27
# -------------------------------------------------------------------------------
import pytest
import json
import allure

from common.get_common_headers import get_headers_dict
from common.utils import Utils
from common.apiRequests import ApiRequest
from common.logger import logger
from config.config import basepath

# path_name = "test_Purchase_receipt_order_list.yml"
file_path = basepath+"/testData/test_Purchase_receipt_order_list.yml"

@allure.feature("采购入库订单模块")
class TestPurchaseReceiptOrderList:

    @pytest.mark.parametrize("test_case",Utils.get_test_cases(file_path))
    def test_PurchaseReceiptOrderList(self,test_case,base_url):
        requests_data = json.dumps(test_case)
        requests_data = Utils.replace_request_data(requests_data)
        test_case = json.loads(requests_data)
        method = test_case['method']
        url = test_case["url"]
        mime_type = test_case["mime_type"]
        payload = test_case["payload"]
        headers = get_headers_dict()
        files = test_case["files"] if "files" in test_case else None
        extract = test_case["extract"] if "extract" in test_case else None
        validate = test_case["validate"] if "validate" in test_case else None
        response = ApiRequest(base_url).send(method, url, mime_type, payload=payload, headers=headers, files=files)
        print(response)
        if extract:  # 提取数据
            logger.info(f'--要提取的数据---\n{extract}')
            Utils.extract(response, extract)
        #
        if validate: # 断言数据
            logger.info(f"--预期断言的数据---\n{validate}")
            Utils.validate(response,validate)